<template>
	<view>
		<!-- 页首 -->
		<zw-header></zw-header>
		<menu-wrapper active-index="2-1" style="background-color: #fff;padding: 0;">
			<view style="display: flex;justify-content:space-between;align-items: center;margin-top: 25px;">
				<view class="lable">我的创作</view>
				<view style="display: flex;justify-content: flex-start;align-items: center;" v-if="!ispl">
					<fui-search-bar background="transparent" @search="search"></fui-search-bar>

					<view class="publish" @click="clickOption(3)">
						<view>
							发布状态
						</view>
						<fui-icon name="arrowdown" color="#000" size="48" style="margin-left: 20rpx;"></fui-icon>
					</view>
					<view class="publish" @click="clickOption(3)">
						<view>
							画面尺寸
						</view>
						<fui-icon name="arrowdown" color="#000" size="48" style="margin-left: 20rpx;"></fui-icon>
					</view>
					<view class="publish" @click="ispl=true">
						<!-- <image src="/static/image/home/fb.png" style="width: 34rpx;height:30rpx;margin-right: 20rpx;">
						</image> -->
						<fui-icon name="edit" color="#000" size="48" style="margin-right: 20rpx;"></fui-icon>
						<view>
							批量选择
						</view>
					</view>
				</view>
				<view style="display: flex;justify-content: flex-start;align-items: center;" v-if="ispl">
					<view class="publish" @click="addGroup()">
						<view>
							加入合集
						</view>
					</view>
					<view class="publish" @click="showQx()">
						<fui-icon name="pulldown" color="#000" size="48" style="margin-right: 20rpx;"></fui-icon>
						<view>
							下载
						</view>
					</view>
					<view class="publish" @click="showQx()">
						<fui-icon name="delete" color="#000" size="48" style="margin-right: 20rpx;"></fui-icon>
						<view>
							删除
						</view>
					</view>
					<view class="publish" @click="ispl=false">
						<view>
							取消
						</view>
					</view>
				</view>
			</view>
			<view class="card-body">
				<view class="container">
					<view>
						<fui-checkbox-group name="checkbox" v-model="vals" @change="change">

							<scroll-view scroll-y @scrolltolower="getList">
								<view
									style="display: flex;flex-wrap: wrap;margin-bottom: 100rpx;align-items: flex-start;">
									<view v-for="(item,index) in data"
										style="width: 16%;position: relative;margin-top: 34rpx;" @click="info(item)">
										<view style="position: absolute;right: 15%;top: 20rpx;z-index: 3;" v-if="ispl">
											<fui-checkbox :value="item.id+''"></fui-checkbox>
										</view>
										<view style="position: relative;">
											<image :src="item.path"
												style="width: 90%;border-radius: 28rpx;background-color: rgba(0, 0, 0, 0.5);position: relative;"
												mode="widthFix">
											</image>
											<view v-if="ispl"
												style="top: 0;background-color: rgb(0, 0, 0);opacity: 0.6;width: 90%;height: 99%;position: absolute;z-index: 2;border-radius: 28rpx;">

											</view>
										</view>
									</view>
								</view>
							</scroll-view>
						</fui-checkbox-group>
					</view>
					<fui-empty isFixed width="200" v-if="data.length==0" height="200" marginTop="400"
						src="../../static/image/user/empty.png" title="暂无数据"></fui-empty>
				</view>
			</view>
		</menu-wrapper>
		<fui-landscape :show="show" :closable="closable" @close="closePopup">
			<view class="fui-ani__box"
				style="background-color: #fff;border-radius: 28rpx;width: 720rpx;height: 450rpx;">
				<view class="flex-center"
					style="height:120rpx;display: flex;justify-content: center;align-items: center;padding: 0 40rpx 0 40rpx;">
					<view style="color: #000000;font-weight: bold;font-size: 48rpx;">确认删除</view>
				</view>
				<view class="flex-center"
					style="height:120rpx;display: flex;justify-content: center;align-items: center;padding: 0 40rpx 0 40rpx;">
					<view style="color: #666666;font-weight: 500;font-size: 32rpx;">确认删除后生成作品将无法恢复</view>
				</view>
				<view style="padding:80rpx;display: flex;justify-content: space-between;align-items: center;">
					<view @click="closePopup"
						style="background: #D8D8D8;border-radius: 200rpx;font-size: 36rpx;font-weight: bold;color: #3D3D3D;padding: 15rpx 90rpx 15rpx 90rpx">
						取消
					</view>
					<view @click="deletePost()"
						style="background: #0033FF;border-radius: 200rpx;font-size: 36rpx;font-weight: bold;color: #fff;padding: 15rpx 90rpx 15rpx 90rpx">
						确定
					</view>
				</view>
			</view>
		</fui-landscape>
		<fui-landscape :show="showGroup" :closable="false" @close="closePopup1">
			<view class="fui-ani__box" style="background-color: #fff;border-radius: 28rpx;width: 800rpx;">
				<view class="flex-center"
					style="height:120rpx;display: flex;justify-content: space-between;align-items: center;padding: 0 40rpx 0 40rpx;">
					<view style="color: #000000;font-weight: bold;font-size: 48rpx;">加入合集</view>
					<image src="/static/image/user/content/close.png" style="width: 80rpx;height: 80rpx;"
						@click="closePopup1"></image>
				</view>
				<view class="flex-center"
					style="display: flex;justify-content: center;align-items: center;padding: 0 40rpx 0 40rpx;">
					<scroll-view scroll-y>
						<fui-radio-group name="radio" v-model="ids" @change="change">
							<view v-for="(item,index) in groupList"
								style="display: flex;justify-content: space-between;align-items: center;">
								<view class="fui-align__center">
									<fui-radio :value="item.id" checked></fui-radio>
									<fui-tag text="私有" v-if="item.visible==0" color="#fff" :scaleRatio="0.8"
										background="#000" style="margin-left: 30rpx;"></fui-tag>
									<fui-tag text="公开" v-if="item.visible==1" color="#fff" :scaleRatio="0.8"
										background="#D000FF" style="margin-left: 30rpx;"></fui-tag>
									<text class="fui-text"
										style="margin-left: 20rpx;color: #000000;font-size: 14px;">{{item.name}}</text>
								</view>
								<view class="fui-align__center">
									<text class="fui-text"
										style="color: #000000;font-size: 14px;margin-right: 10rpx;">0组</text>
								</view>
							</view>
						</fui-radio-group>
					</scroll-view>
				</view>
				<view
					style="padding:80rpx 40rpx 40rpx 40rpx;display: flex;justify-content: space-between;align-items: center;">
					<view @click="newGroup=true"
						style="width: 35%;text-align: center; background: #D8D8D8;border-radius: 200rpx;font-size: 36rpx;font-weight: bold;color: #3D3D3D;padding: 15rpx 90rpx 15rpx 90rpx">
						新建合集
					</view>
					<view @click="addGroups()"
						style="cursor: pointer; margin-left: 20rpx;width: 35%;text-align: center;background: #0033FF;border-radius: 200rpx;font-size: 36rpx;font-weight: bold;color: #fff;padding: 15rpx 90rpx 15rpx 90rpx">
						确定
					</view>
				</view>
			</view>
		</fui-landscape>
		<fui-landscape :show="newGroup" :closable="false" @close="closePopup2">
			<view class="fui-ani__box" style="background-color: #fff;border-radius: 28rpx;width: 800rpx;">
				<view class="flex-center"
					style="height:120rpx;display: flex;justify-content: space-between;align-items: center;padding: 0 40rpx 0 40rpx;">
					<view style="color: #000000;font-weight: bold;font-size: 48rpx;">新建合集</view>
					<image src="/static/image/user/content/close.png" style="width: 80rpx;height: 80rpx;"
						@click="closePopup2"></image>
				</view>
				<view class="flex-center" style="padding: 0 40rpx 0 40rpx;">
					<view style="padding: 0rpx 50rpx 0rpx 50rpx;">
						<fui-input :marginTop="24" backgroundColor="#F0F0F0" color="#6D6D6D"
							placeholderStyle="color: #5E5E5E;font-size: 14px;" :radius="20" border-color="#C4BFBF"
							inputBorder placeholder="请输入合集名称" v-model="geroup.name"></fui-input>
					</view>
					<view style="padding: 40rpx 50rpx 0rpx 50rpx;">
						<fui-textarea :radius="20" textareaBorder placeholderStyle="color: #5E5E5E;font-size: 14px;"
							border-color="#C4BFBF" background-color="#F0F0F0" v-model="geroup.content" color="#6D6D6D"
							placeholder="分享合集背后的故事（选填）"></fui-textarea>
					</view>
					<view style="padding: 40rpx 50rpx 0rpx 50rpx;">
						<piaoyi-select ref="piaoyiSelect" placeholder="请选择分类" :options="options"></piaoyi-select>
					</view>
					<view style="padding: 40rpx 50rpx 0rpx 50rpx;">
						<!-- <piaoyi-select :inputValue.sync="geroup.label"  ref="piaoyiSelect" placeholder="请选择当前分类关键词"
							:options="options"></piaoyi-select> -->
					</view>
					<view style="padding: 40rpx 50rpx 0rpx 50rpx;">
						<fui-radio-group name="radio" v-model="geroup.visible" @change="change">
							<view class="fui-align__center">
								<fui-radio value="0" checked></fui-radio>
								<fui-tag text="私有" color="#fff" scaleRatio="0.8" background="#000"
									style="margin-left: 30rpx;"></fui-tag>
								<text class="fui-text"
									style="margin-left: 20rpx;color: #5E5E5E;font-size: 14px;">仅自已可见</text>
							</view>
							<view class="fui-align__center">
								<fui-radio value="1"></fui-radio>
								<fui-tag text="公开" color="#fff" scaleRatio="0.8" background="#D000FF"
									style="margin-left: 30rpx;"></fui-tag>
								<text class="fui-text"
									style="margin-left: 20rpx;color: #5E5E5E;font-size: 14px;">所有人可见</text>
							</view>
						</fui-radio-group>
					</view>
				</view>
				<view
					style="padding:60rpx;display: flex;justify-content:center;align-items: center;margin-top: 53px;border-top: 1px solid #F0F0F0;">
					<view @click="addNewGroup()"
						style="width: 100%;background: #0033FF;border-radius: 200rpx;font-size: 36rpx;font-weight: bold;color: #fff;padding: 15rpx 90rpx 15rpx 90rpx;text-align: center;">
						确定
					</view>
				</view>
			</view>
		</fui-landscape>
	</view>
</template>

<script>
	import menuWrapper from '@/components/user/common/menu-wrapper.vue';
	import centerConfig from '@/common/config/user/center.config.js';

	import {
		mapState
	} from 'vuex';

	export default {
		components: {
			menuWrapper
		},
		data() {
			return {
				ids: [],
				options: [{
					label: '鞋样设计',
					value: '鞋样设计'
				}, {
					label: '服装设计',
					value: '服装设计'
				}, {
					label: '箱包设计',
					value: '箱包设计'
				}, {
					label: '图标设计',
					value: '图标设计'
				}, {
					label: '饰品设计',
					value: '饰品设计'
				}],
				inputValue: '',
				newGroup: false,
				ispl: false,
				showGroup: false,
				...centerConfig,
				accountInfo: {},
				counts: [],
				tabIndex: 1,
				data: [],
				page: 0,
				nameKey: '',
				vals: [],
				show: false,
				closable: false,
				groupList: [],
				geroup: {
					name: '',
					content: '',
					status: 1,
					label: 1,
					image: "",
					formatImages: [],
					type: 4,
					visible: '1',
				}
			}
		},
		computed: {
			...mapState(['loginUser']),
			currentTime() {
				const currentHour = new Date().getHours();
				const timeQuantums = ['凌晨', '上午', '下午', '晚上'];
				return timeQuantums[Math.floor(currentHour / 6)];
			}
		},
		onLoad(op) {
			this.tabIndex = op.tabIndex;
			this.getList();
			this.requstGroupData();
			this.$store.commit('tab', 0);
		},
		onReachBottom() {
			console.log('下拉加载')
			this.getList()
		},
		methods: {
			addGroups(item) {
				var list = [];
				const that = this;
				console.log('vals',this.vals)
				for (var i = 0; i < this.data.length; i++) {
					var item = this.data[i];
					console.log('item',item.id)
					if (this.vals.find(el=>el==item.id)) {
						list.push(item)
					}
				}
				console.log(list)
				console.log('ids',this.ids)
				this.$util.request('/api/v1/pictureCollection/addGroup/' + this.ids, list, (res) => {
					uni.showToast({
						title: "操作成功",
						icon: 'none' 
					})
					that.closePopup1()
					that.requstGroupData();
				}, false, "PUT");
			},
			addNewGroup() {
				const that = this;
				this.geroup.visible = parseInt(this.geroup.visible)
				this.$util.request('/api/v1/pictureCollection', this.geroup, (res) => {
					uni.showToast({
						title: "合集创建成功",
						icon: 'none'
					})
					that.newGroup = false
					that.requstGroupData();
				}, false);

			},
			info(item) {
				uni.navigateTo({
					url: '/pages/works/info?id=' + item.jobId
				})
			},
			showQx() {
				if (this.vals.length > 0) {
					this.show = true
				} else {
					uni.showToast({
						title: '请选择帖子',
						icon: 'none'
					})
				}
			},
			addGroup() {
				if (this.vals.length > 0) {
					this.showGroup = true
				} else {
					uni.showToast({
						title: '请选择帖子',
						icon: 'none'
					})
				}
			},
			closePopup() {
				this.show = false
			},
			closePopup1() {
				this.showGroup = false
			},
			closePopup2() {
				this.newGroup = false
			},
			change(e) {
				console.log(e)
			},
			goUrl(url) {
				uni.navigateTo({
					url: url,
					fail(err) {
						console.log(err)
					}
				})
			},
			clickOption(index) {
				if (this.vals.length <= 0) {
					uni.showToast({
						title: '请选择作品',
						icon: 'none'
					})
					return false;
				}
				uni.setStorage({
					data: this.vals,
					key: 'picture'
				})
				this.goUrl('/pages/publish/picture')
			},
			getList() {
				let that = this;
				var cmd = '';
				if (this.nameKey) {
					cmd = this.nameKey
				}
				this.$util.request('/api/v1/myphoto/mine', {
					page: that.page,
					cmd: cmd
				}, (res) => {
					console.log('myphoto', res)
					if (res.data.length > 0) {
						that.page = that.page + 1;
					}
					that.data = that.data.concat(res.data)
				}, true);
			},
			deletePost() {
				let that = this;
				for (var i = 0; i < this.vals.length; i++) {
					// this.vals[i]
					this.$util.request('/api/v1/pictureCollection/delete/' + this.vals[i], {}, (res) => {
						console.log('pictureCollection', res.data)
					}, true);
				}
				this.getList();
				this.show = false
				this.ispl = false
			},
			requstGroupData() {
				const that = this;
				this.$util.request('/api/v1/pictureCollection/mine', {
					page: 0,
					orderType: 2,
					type: 4
				}, (res) => {
					console.log('返回正确回调post', res)
					that.groupList = res.data;
				}, true);
			},
		}
	}
</script>

<style lang="scss">
	.fui-align__center {
		display: flex;
		justify-content: flex-start;
		align-items: center;
	}

	.wrap {
		display: -webkit-box;
		-webkit-line-clamp: 3;
		-webkit-box-orient: vertical;
		overflow: hidden;
		text-overflow: ellipsis;
	}

	.bottom-item {
		display: flex;
		justify-content: center;
		align-items: center;
		margin-left: 30rpx;

		.image {
			margin-right: 10rpx;
			width: 20rpx;
			height: 20rpx;
		}
	}




	.card-body {
		margin-top: 60rpx;
	}

	.lable {
		font-family: Source Han Sans;
		font-size: 80rpx;
		font-weight: bold;
		font-feature-settings: "kern" on;
		color: #3D3D3D;

	}

	.publish {
		background: #FFFFFF;
		height: 70rpx;
		color: #000000;
		border-radius: 100rpx;
		font-size: 28rpx;
		padding: 0rpx 30rpx 0rpx 30rpx;
		display: flex;
		justify-content: center;
		align-items: center;
		border: 1px solid #C4BFBF;
		margin-right: 40rpx;
	}
</style>